#
# GIMnetAP Commonlib Makefile
# - In charge of building GIMnetAP common library
#
#
# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS $(CE)
INCLUDES=-I../../include/utils -I../ -I../protocol
WFLAGSC=-Wall -Wunused -Wshadow
WFLAGSCPP=-Wall -Wunused -Wshadow -Weffc++
WFLAGSDCPP=
CFLAGS=-O0 -g3 $(WFLAGSC) $(INCLUDES) $(EXTRADEFS)
CPPFLAGS=-O0 -g3 $(WFLAGSCPP) $(INCLUDES) $(EXTRADEFS)
DCPPFLAGS=-O0 -g3 $(WFLAGSDCPP) $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=-lrt -lpthread
VPATH=
INCLUDE_EXPORT=../../include

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS)



# Define targets
TARGETS=libGIMnetAP-common.a libGIMnetAP-common.include

# All rule compiles all per default
.PHONY: all
all: $(TARGETS)

###############################################
.PHONY: libGIMnetAP-common.include
libGIMnetAP-common.include:
	mkdir -p ./include
	rm -f ./include/*.h
	cp -v *.h ./include

	mkdir -p $(INCLUDE_EXPORT)/GIMnetAP
	cp -v ./include/* $(INCLUDE_EXPORT)/GIMnetAP
	chmod 640 $(INCLUDE_EXPORT)/GIMnetAP/*.h

###############################################

LIBGIMNETAPCOMMON_SRCS_C = apsecurity.c buffer.c connection.c		\
                           connectionTCP.c connectionUDP.c		\
                           connectionUNIX.c hubctrl_common.c idmap.c	\
                           msgreplybuffer.c protocolDispatcher.c	\
                           strmap.c
LIBGIMNETAPCOMMON_OBJS = $(LIBGIMNETAPCOMMON_SRCS_C:.c=.o)
libGIMnetAP-common.a: $(LIBGIMNETAPCOMMON_OBJS)
	@ar rv $@ $?
	@echo "      [AR] $@"
	@ranlib $@
	@echo "      [RANLIB] $@"
###############################################

.PHONY: libGIMnetAP-common.a-dist
libGIMnetAP-common.a-dist: libGIMnetAP-common.a
	@echo "      [STRIP] libGIMnetAP-common.a"
	@strip --strip-debug libGIMnetAP-common.a

	@echo "      [COPY] libGIMnetAP-common.a libGIMnetAP-common.a$(PLATFORMBITS).a"
	@if [ "`uname -m`" == "x86_64" ]; \
	   then cp -v libGIMnetAP-common.a libGIMnetAP-common64.a; \
	   else cp -v libGIMnetAP-common.a libGIMnetAP-common32.a; \
	 fi
###############################################

.PHONY: local-clean clean real-clean realclean
local-clean clean real-clean realclean:
	@rm -f *.o *.opp *.dopp libGIMutils* 
	@echo "     [CLEAN]"

########### Compile rules ####################
# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

# Compile rule for all .dopp (dirty .cpp) files
%.dopp:	%.cpp
	@$(COMPILEDCPP) -o $@ $<
	@echo "      [DIRTY-CXX] $<"

##############################################
##############################################
##############################################
